import React, { Component } from "react";
import { getAppPlatformsDatas } from "../../Redux/Action/nativeDatas/nativeDatas";
import { connect } from "react-redux";

import "./index.scss";
import fetch from "isomorphic-fetch";

// let orderParams = {
//   merchantId: "T100100",
// userId: "55771",
// mobile: "13677669737",
//   userId: "019121",
//   mobile: "13527496722",
//   orderCode: "10001",
//   orderName: "测试",
//   pay_amount: "0.001",
//   shipping_address: "测试地址",
//   consignee_tel: "10086",
//   consignee: "测试收货人"
// };
// "55771  019126",
let homeParams = {
	merchantId: "T100100",
	// userId: "019121",
	// mobile: "13527496722"
	// userId: "55771",
	// mobile: "13677669737"
	// userId: "42280",
	// mobile: "18580426830"
	userId: "282970",
	mobile: "13658389625"
};
// let h5HostUrl = "https://xwf-test.yonghui.cn/XwfLoanFrontServiceUAT"; // uat接口地址
// let h5HostUrl = "http://10.0.68.154:8080/LoanFrontService"; // dev环境
// let h5HostUrl = "http://10.10.234.79:8080/LoanFrontService"; // 雪韬本地
// let h5HostUrl = "http://192.168.101.220:8081/LoanFrontService"; // 何亮本地

/**
 * 测试类
 * @param {*} props
 */
class InitSdk extends Component {
	componentDidMount() {
		const initParams = homeParams;
		fetch(
			// "http://10.0.68.140:8080/LoanFrontService/test/getSignAndData/0",
			// "https://xwf-test.yonghui.cn/XwfLoanFrontServiceUAT/test/getSignAndData/0",
			"http://10.0.68.154:8080/LoanFrontService/sdkSignAndData/getSignAndData/0",
			// "http://192.168.101.220:8081/LoanFrontService/test/getSignAndData/0",
			{
				method: "POST",
				mode: "cors",
				headers: {
					"Content-Type": "application/json;charset=UTF-8"
				},
				body: JSON.stringify(initParams)
			}
		).then(response => {
			response.json().then(resp => {
				console.log(resp);
				let info = resp.data;
				let { sign, data } = info.data;
				let authHeader = JSON.stringify({
					sign, // 签名数据
					data, // 加签的数据
					userId: initParams.userId, // 用户id
					merchantId: initParams.merchantId, // 商户号
					extendJson: "{}", // 扩展数据
					h5Version: "1.0.0", // html5的版本号
					mobile: initParams.mobile, // 注册手机号
					plateform: "web" //平台类型
				});
				this.props._getAppPlatformsDatas({
					authHeader,
					mobile: initParams.mobile
				});
				setTimeout(() => {
					this.props.history.push("");
				}, 200);
			});
		});
		return () => {};
	}
	render() {
		return <div></div>;
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps(dispatch) {
	return {
		_getAppPlatformsDatas: id => {
			//获取native的数据
			dispatch(getAppPlatformsDatas(id));
		}
	};
}

export default connect(mapStateToProps, mapDispatchToProps)(InitSdk);
